<?php
class ManageEmailForm extends Form{
	function ManageUpTinForm(){
		Form::Form('ManageEmailForm');
		CGlobal::$website_title='Quản trị email';
		$this->link_css('style/manage_item.css');
	}

	function draw(){	
		global $display;
		$this->beginForm();
		
		$sql="SELECT COUNT(*) AS total_row FROM spam_mail";
		
		$total			=DB::fetch($sql,'total_row',0);
		$spam_content	=DB::select('spam_content','status=1');
		
		$pagging	='';
		$spam_emails=array();
		
		if($total){
			$limit='';
			
			$pagging=AZPagging::pagingSE($limit,$total,50,10,'page_no',true);	
			$sql="SELECT id, email_list, time, time_modify, spam_id, status FROM spam_mail ORDER BY id DESC $limit";
				
			$re=DB::query($sql);
			
			if($re){
				while($email=mysql_fetch_assoc($re)){	
					if($email['time'] !=$email['time_modify']){
						$email['time']="<b>Tạo:</b> ".date('H\hi d.m.Y',$email['time']);
						$email['time'].="<br /><b>Sửa:</b> ".date('H\hi d.m.Y',$email['time_modify']);
					}
					else{
						$email['time']="<b>Tạo:</b> ".date('H\hi d.m.Y',$email['time']);
					}
					
					if($spam_content && $spam_content['id'] == $email['spam_id']){
						$email['spam_id'] = '<font color="green">Đã spam</font>';
						$email['reset'] = AZLib::button(Url::build_current(array('cmd'=>'reset_email','id'=>$email['id'])),'icon-reload.gif','Spam lại');
					}
					else{
						$email['spam_id'] 	= '<font color="orange">Chưa được Spam</font>';
						$email['reset'] 	= '';
					}
							
					if($email['status']){
						$email['status'] = '<font color="green">Có</font>';
						$email['check'] = AZLib::button(Url::build_current(array('cmd'=>'deactive_email','id'=>$email['id'])),'admin/delete_button_dis.gif','Không cho phép spam');
					}
					else{
						$email['status'] = '<font color="orange">Không</font>';
						$email['check'] = AZLib::button(Url::build_current(array('cmd'=>'active_email','id'=>$email['id'])),'admin/check.gif','Cho phép spam');
					}
							
					if($email['email_list']){	
						$email['email_list'] = count(explode("\n",$email['email_list']));	
					}
					else	
						$email['email_list'] = 0;	
					
					$email['edit_link'] = Url::build_current(array('cmd'=>'edit_email',		'id'=>$email['id']));
					$email['del_link']  = Url::build_current(array('cmd'=>'delete_email',	'id'=>$email['id']));
					
					$spam_emails[$email['id']] = $email;															
				}
			}
		}
		
		$display->add('check_all',AZLib::button(Url::build_current(array('cmd'=>'active_all_email')),'admin/check.gif','Cho phép spam tất cả các mail'));
		$display->add('check_none',AZLib::button(Url::build_current(array('cmd'=>'deactive_all_email')),'admin/delete_button_dis.gif','Không phép spam tất cả các mail'));
		
		$display->add('items',$spam_emails);
		$display->add('pagging',$pagging);
		$display->output('ManageEmail');
		$this->endForm();
	}
}
?>